cmake_minimum_required(VERSION 2.8)

#-------------------------------------------------------------------------------------------------
#------------------ include directories of ATOMISM and set source files-----------------------------
#-------------------------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMake_FindModules )


message(STATUS "\n----------From src/Molecule/CMakeLists.txt----------")
message(STATUS "Base include directories: ${ATOMISM_BASE_INCLUDE_DIRS}")
message(STATUS "Base libraries: ${ATOMISM_BASE_LIBRARIES}")

SET(VTK   1 CACHE BOOL "if one compile VTK files for 3D visualization")
IF( VTK )
   MESSAGE( STATUS "Compiles VTK files for 3D visualization (-DVTK=0 to desactivate)")
   FIND_PACKAGE(VTK REQUIRED)
ELSEIF( NOT VTK )
   MESSAGE( STATUS "Does not compile VTK files for 3D visualization (-DVTK=1 to activate)")
ENDIF( VTK )

FIND_PACKAGE(GSL REQUIRED)

FILE(GLOB MOLECULE_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp )
FILE(GLOB BASE_HEADER  ${CMAKE_CURRENT_SOURCE_DIR}/*.h )
IF( VTK )
   FILE(GLOB MOLECULE_SRC  ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp  ${CMAKE_CURRENT_SOURCE_DIR}/3D/*.cpp)
   FILE(GLOB BASE_HEADER  ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/3D/*.h)
   INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/3D)
ENDIF( VTK )

include_directories( ${GSL_INCLUDE_DIRS} )
include_directories( ${VTK_INCLUDE_DIRS} )
include(${VTK_USE_FILE})

INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR}/  ${ATOMISM_BASE_INCLUDE_DIRS}/ )

#-------------------------------------------------------------------------------------------------
#------------------ compile library base --------------------------------------------------------
#-------------------------------------------------------------------------------------------------

add_library ( molecule   SHARED ${MOLECULE_SRC}  ) 

IF( NOT COVERAGE )
   SET_TARGET_PROPERTIES( molecule PROPERTIES COMPILE_FLAGS -fPIC )
   SET_TARGET_PROPERTIES( molecule PROPERTIES COMPILE_FLAGS -O3 )
ENDIF(NOT COVERAGE )


TARGET_LINK_LIBRARIES( molecule ${ATOMISM_BASE_LIBRARIES} ${GSL_LIBRARIES} ${VTK_LIBRARIES} )
set_target_properties(molecule PROPERTIES  SUFFIX .so)

SET( ATOMISM_MOLECULE_INCLUDE_DIRS  ${CMAKE_CURRENT_SOURCE_DIR}  ${GSL_INCLUDE_DIRS}  )
SET( ATOMISM_MOLECULE_LIBRARIES     molecule  ${GSL_LIBRARIES}  ${VTK_LIBRARIES})

IF( VTK )
   SET( ATOMISM_MOLECULE_INCLUDE_DIRS  ${ATOMISM_MOLECULE_INCLUDE_DIRS}  ${CMAKE_CURRENT_SOURCE_DIR}/3D ${VTK_INCLUDE_DIRS}  )
   SET( ATOMISM_MOLECULE_LIBRARIES     ${ATOMISM_MOLECULE_LIBRARIES}      ${VTK_LIBRARIES}  )
ENDIF( VTK )

foreach(next_ITEM ${MOLECULE_SRC})
   file(APPEND ${LAUNCHER_FILE} "#include<${next_ITEM}>\n" )
endforeach(next_ITEM ${MOLECULE_SRC})

INSTALL(FILES  ${BASE_HEADER} DESTINATION ${CMAKE_INSTALL_PREFIX}/include )






